package reviews.task4;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import reviews.task2.UserScoreMapper;
import reviews.task2.UserScoreReducer;

/**
 * 4.评价最有价值的前10个用户信息
 */
public class UserHelpfulnessDriver {

    /**
     * 本次MapReduce输入的数据路径
     */
    private static final String inputPathString = "input/input-task1/Reviews.csv";
    /**
     * 本次MapReduce输出的数据路径
     */
    private static final String outputPathString = "output/output-task4/";

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        // 1.指定本次MapReduce的job的ar包运行主类
        job.setJarByClass(UserHelpfulnessDriver.class);
        // 2.指定本次MapReduce所用的Mapper类
        job.setMapperClass(UserHelpfulnessMapper.class);
        // 3.指定本次MapReduce所用的Reducer类
        job.setReducerClass(UserHelpfulnessReducer.class);
        // 4.指定本次Map阶段的输出的Key类型
        job.setMapOutputKeyClass(Text.class);
        // 5.指定本次Map阶段的输出的Value类型
        job.setMapOutputValueClass(IntWritable.class);
        // 6.指定本次Reducer阶段的输出的Key类型
        job.setOutputKeyClass(Text.class);
        // 7.指定本次Map阶段的输出的Value类型
        job.setOutputValueClass(IntWritable.class);
        // 8.指定本次MapReduce输入的数据路径
        FileInputFormat.setInputPaths(job, new Path(inputPathString));
        // 9.指定本次MapReduce输出的数据路径
        FileOutputFormat.setOutputPath(job, new Path(outputPathString));
        // 10.提交MapReduce程序，并且监控打印程序执行情况
        job.waitForCompletion(true);
    }

}
